package com.ff.discounts.component.tab.home

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.ff.discounts.R
import com.ff.discounts.component.free.FreeActivity
import com.ff.discounts.component.search.SearchActivity
import com.ff.discounts.databinding.FragmentHomeBinding
import com.ff.discounts.fragment.BaseViewModelFragment

/**
 *追剧
 * @author: fufang
 * @date: 2023/10/17
 */
class HomeFragment : BaseViewModelFragment<FragmentHomeBinding>() {
    private lateinit var navAdapter: NavAdapter
    private lateinit var goodsAdapter: GoodsAdapter

    override fun initDatum() {
        super.initDatum()
        //绑定navAdapter
        navAdapter = NavAdapter()
        binding.navList.adapter = navAdapter
        navAdapter.submitList(historyDataList)

        // 绑定goodsAdapter
        goodsAdapter = GoodsAdapter()
        binding.goodsList.adapter = goodsAdapter
        goodsAdapter.submitList(historyDataList)


    }

    override fun initListeners() {
        super.initListeners()
        binding.searchContainer.setOnClickListener {
            startActivity(SearchActivity::class.java)
        }
        binding.free.setOnClickListener {
            startActivity(FreeActivity::class.java)
        }
    }

    override fun initViews() {
        super.initViews()


        //适配器水平布局
       binding.navList.apply {
           layoutManager = LinearLayoutManager(hostActivity)
           (layoutManager as LinearLayoutManager).orientation = LinearLayoutManager.HORIZONTAL;
       }

        binding.goodsList.apply {
            layoutManager = LinearLayoutManager(hostActivity)

        }


    }



    companion object{
        fun newInstance():HomeFragment{
            val args = Bundle()
            val fragment = HomeFragment()
            fragment.arguments = args
            return fragment
        }

        private val historyDataList = mutableListOf<HistoryData>(
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集")

        )
    }
}